

include config.mak

OBJECTS=memory.o llist.o que.o pio.o body.o world.o thread.o pmath.o
TEST_PROGS=llist_test physm_test
INCLUDE=-I. -I../lib/include
PHYSM_LIBS=-L../lib -lmatvec -lmatvec_asm -lpthread -lm -lc
LIBS=-L. -lphysm $(PHYSM_LIBS)

LD_FLAGS=-shared -soname libphysm.so -o libphysm.so.$(VERSION)

### Main targets

all: physm-info physm $(TEST_PROGS)
	cp $(TEST_PROGS) ../bin
	cp -f libphysm.so.$(VERSION) ../bin
	cd ../bin && ldconfig -v -n .

physm: $(OBJECTS)
	ld $(LD_FLAGS) $(PHYSM_LIBS) $(OBJECTS)
	ldconfig -v -n .

### Source compiling targets

.c: physm
	$(CC) $(C_TEST_FLAGS) -o $@ $(CPP_FLAGS) $(INCLUDE) $(LIBS) $<

.c.o:
	$(CC) $(C_FLAGS) $(CPP_FLAGS) $(INCLUDE) $<

### Other targets

physm-info:
	@echo "+----------------------------------------------------------+"
	@echo "Building physm version $(VERSION)"
	@echo "  CC:           $(CC)"
	@echo "  C_FLAGS:      $(C_FLAGS)"
	@echo "  C_TEST_FLAGS: $(C_TEST_FLAGS)"
	@echo "  CPP_FLAGS:    $(CPP_FLAGS)"
	@echo "  OBJECTS:      $(OBJECTS)"
	@echo "  TEST_PROGS:   $(TEST_PROGS)"
	@echo "  INCLUDE:      $(INCLUDE)"
	@echo "  LIBS:         $(LIBS)"

### Cleaning targets

clean: clean-bin clean-src

clean-src:
	rm -f *.o
	rm -f libphysm*
	rm -f $(TEST_PROGS)

clean-bin:
	cd ../bin && rm -f *